import 'package:flutter/material.dart';
import 'package:flutter_section_table_view/flutter_section_table_view.dart';
import 'package:ls_work/a_yyt/models/pending_selected_group_entity.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';

class PendingSelectedGroupPage extends StatefulWidget {
  List<List<PendingSelectedGroupEntity>> sortList = [];
  PendingSelectedGroupPage({Key? key,required this.sortList});
  @override
  _PendingSelectedGroupPageState createState() =>
      _PendingSelectedGroupPageState();
}

class _PendingSelectedGroupPageState extends State<PendingSelectedGroupPage> {
  @override
  Widget build(BuildContext context) {
    return SectionTableView(
      sectionCount: widget.sortList.length,
      numOfRowInSection: (section) {
        return widget.sortList[section].length;
      },
      cellAtIndexPath: (section, row) {
        return Container(
          height: 60.0,
          padding: EdgeInsets.only(left: 30, right: 30),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Text(' ${widget.sortList[section][row].name}',style: TextStyles.textDark18,),
              Checkbox(
                value: widget.sortList[section][row].isSelected,
                onChanged: (value) {
                  setState(() {
                    widget.sortList[section][row].isSelected = value;
                    if (value==true) {
                      for (PendingSelectedGroupEntity info
                          in widget.sortList[section]) {
                        if (info.name != widget.sortList[section][row].name) {
                          info.isSelected = false;
                        }
                      }
                    }
                  });
                },
              )
            ],
          ),
        );
      },
      headerInSection: (section) {
        return Container(
          height: 64.0,
          padding: EdgeInsets.only(left: 30),
          color: Colours.bg_color,
          alignment: Alignment.centerLeft,
          child: Text(
            ' ${widget.sortList[section].first.serviceTypeName}',
            style: TextStyles.textDark20,
          ),
        );
      },
      divider: Container(
        color: Colours.line,
        height: 1.0,
      ),
    );
  }
}
